package com.example.yskjproject.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.yskjproject.R;
import com.example.yskjproject.adapter.BottomSheetAdapter;
import com.example.yskjproject.model.BottomListDataModel;
import com.google.common.collect.Lists;
import com.tencent.cloud.tuikit.roomkit.model.entity.UserEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * BottomSheetDialog   底部dialog
 * <p>
 * 作者：zx
 * 创建时间：2024/5/14
 */
public class BottomSheetDialog extends DialogFragment {

    RecyclerView recyclerView;
    private Context context;
    private BottomSheetAdapter bottomSheetAdapter;
    private List<BottomListDataModel> listBottomDate = Lists.newArrayList();

    private List<UserEntity> mUserList;


    public BottomSheetDialog(Context context
//            ,List<UserEntity> mUserList
    ) {
        this.context = context;
        this.mUserList = mUserList;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // 加载布局文件
        View view = inflater.inflate(R.layout.dialog_bottom, container, false);
        // 初始化视图
        recyclerView = view.findViewById(R.id.rv_member);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 设置DialogFragment的参数，使其显示在底部
        Dialog dialog = getDialog();
        if (dialog != null) {
            dialog.setCancelable(true);
            dialog.setCanceledOnTouchOutside(true);

            Window window = dialog.getWindow();
            if (window != null) {
                window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                window.setGravity(Gravity.BOTTOM);
            }
        }
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        bottomSheetAdapter = new BottomSheetAdapter(listBottomDate);
        recyclerView.setAdapter(bottomSheetAdapter);
    }
}
